package com.example.parse_springboot.controller;

import com.example.parse_springboot.entity.Result;
import com.example.parse_springboot.entity.User;
import com.example.parse_springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result<String> login(String username, String password) {
        String token;
        try {
            token = userService.loginService(username, password);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.success(token);
    }

    @PostMapping("/register")
    public Result<String> register(String username, String password) {
        try {
            User register = userService.register(username, password);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.success("注册成功");
    }
}
